﻿/*******************************************************************
 *     JameE
 *******************************************************************
  Copyright 2010 Clifford Champion and JameE contributors.
  
  This file is part of JameE.
  
  JameE is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  JameE is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with JameE.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************/

/// <reference path="~/Base/Classer.js" />
/// <reference path="~/Base/IncludeLoader.js" />

$include(
[
	
]);

$class_static(
"JameE.Engine.MessageTypes",
{
	/////////////////////
	// CONSTANTS
	/////////////
	UNKNOWN: 0

	// global raw mouse
	, MOUSE_MOVE_RAW:	101
	, MOUSE_DOWN_RAW:	102
	, MOUSE_UP_RAW:		103
	, MOUSE_CLICK_RAW:	104
	
	// global transformed mouse
	, MOUSE_MOVE_GLOBAL:	111
	, MOUSE_DOWN_GLOBAL:	112
	, MOUSE_UP_GLOBAL:		113
	, MOUSE_CLICK_GLOBAL:	114

	// keyboard
	, KEY_DOWN:			201
	, KEY_UP:			202

	// collision detection
	, MOUSE_TOUCH:		401

	// start of custom range
	, CUSTOM:			10000

	// max value
	, MAX_VALUE:		0xFFFFFFFE
});

$class(
"JameE.Engine.Message",
{
	/////////////////////
	// FIELDS
	/////////////
	_oTo: null,
	_oFrom: null,
	_iMessage: 0,
	_oData: null,


	/////////////////////
	// CONSTRUCTOR
	/////////////
	_ctor: function () {
		this._oTo = $argument("to") || null;
		this._oFrom = $argument("from") || null;
		this._iMessage = $argument("message", "number") || JameE.Engine.MessageTypes.UNKNOWN;
		this._oData = $argument("data") || null;
	},


	/////////////////////
	// METHODS
	/////////////
	getMessage: function () {
		return this._iMessage;
	},

	getData: function (strKey) {
		if (this._oData === null) {
			return null;
		}

		if (strKey != null) {
			return this._oData[strKey] || null;
		}

		return this._oData;
	},

	getTo: function () {
		return this._oTo;
	},

	getFrom: function () {
		return this._oFrom;
	},

	clone: function () {
		/// <summary>Performs a shallow clone of the message and member-wise 
		/// shallow clone of any message data.</summary>
		var oClone = new JameE.Engine.Message(
			{
				to: this._oTo,
				from: this._oFrom,
				message: this._iMessage,
				data: null
			})
		;
		if (this._oData !== null) {
			var oData = oClone._oData = {};
			var oDataSource = this._oData;
			for (var k in oDataSource) {
				if (!oDataSource.hasOwnProperty(k)) {
					continue;
				}
				oData[k] = oDataSource[k];
			}
		}
		return oClone;
	}
});

$include_notify("Engine/Message.js");
